<div class="page-header no-breadcrumb font-header">录入设备</div>
<div class="content-wrap">
    <div class="panel panel-default">
        <!--panel-body-->
        <div class="panel-body">
            <div class="form-horizontal font-12">
                <form class="form-horizontal bv-form" method="post" id="defaultForms">
                    <div class="cloneCreate">
                        <div class="Equiment-Add border-bottom co-padding-b clearfix">
                            <div class="form-group row">
                                <label class="col-sm-2 control-label">设备MAC码</label>

                                <div class="col-sm-8">
                                    <input type="text" placeholder="请输入设备MAC码" class="form-control macName"/>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="col-sm-2 control-label">设备备注</label>

                                <div class="col-sm-8">
                                    <input type="text" placeholder="请输入设备MAC码" class="form-control macContent"/>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="col-sm-2 control-label">设备组</label>

                                <div class="col-sm-8">
                                    <select class="form-control font-12">
                                        <option>无</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-sm-8 col-sm-offset-2 common-pleft">
                                    <button class="btn btn-danger btn-flat hide" type="button" > <i class="fa fa-minus"></i> 删除该条</button>
                                </div>
                            </div>
                        </div>

                    </div>
                    <div class="row co-padding-b">
                        <div class="col-lg-9 col-lg-offset-3">
                            <button class="btn btn-success btn-flat" type="button" id="clone-btn"> <i class="fa fa-plus"></i> 新增一条</button>
                            <button class="btn btn-primary btn-flat" type="submit">保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <!--panel-body-->


    </div>
</div>

<script>

    $("#select2-devicegroupId-container").click(function(){
        console.log("aaa");
    });

    function delItem(index){
        var obj = $(".Equiment-Add[index="+index+"]");
        obj.remove();
    }

    $("#clone-btn").click(function(){
        var cloneBody = $(".Equiment-Add");
        var len = cloneBody.length;
        if(len>1)
        {
            clone  = cloneBody.last().clone();
        }
        else
        {
            clone = cloneBody.clone();
        }

        clone.attr({'index':len});
        clone.find(".btn-danger").attr({'onClick':'delItem('+len+')'});
        clone.find(".macName").attr({'name':'Equimentname'+len});
        clone.find(".macName").attr({'data-bv-field':'Equimentname'+len});
        clone.appendTo(".cloneCreate");
        $(".Equiment-Add").find(".btn-danger").removeClass("hide");
        $(".Equiment-Add").first().find(".btn-danger").addClass("hide");


        $('#defaultForms').data('bootstrapValidator', null);   //销毁之前监听的bootstrapValidator

        $('#defaultForms').find("button").attr({disabled:false}); //去掉按钮disabled

        validate(); //重新实例化 bootstrapValidator

    });






    /*
     * 数据验证
     * */

    function validate(){
        function randomNumber(min, max) {
            return Math.floor(Math.random() * (max - min + 1) + min);
        };
        $('#captchaOperation').html([randomNumber(1, 100), '+', randomNumber(1, 200), '='].join(' '));
        $('#defaultForms').bootstrapValidator({
//        live: 'disabled',
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {

                MyClass: {
                    selector:'.macName',
                    validators: {
                        notEmpty: {
                            message: '必填'
                        },
                        regexp: {
                            regexp: '[a-zA-Z]{4}',
                            message: '格式不正确'
                        }
                    }
                },
                MyClass1: {
                    selector:'.macContent',
                    validators: {
                        notEmpty: {
                            message: '必填'
                        },
                        regexp: {
                            regexp: '[a-zA-Z]{4}',
                            message: '格式不正确'
                        }
                    }
                }
            }
        });
    }

    $(document).ready(function () {
        validate();
    });

</script>

